import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

//配置持久化
import VuexPersistence from "vuex-persist";
const vuexLocal = new VuexPersistence({
  storage: window.localStorage,//存储的位置
})

export default new Vuex.Store({
  state: {
    dizhiId: '',
    searchList: []
  },
  mutations: {
    tian(state, i) {
      state.dizhiId = i
    },
    qin(state) {
      state.dizhiId = ''
    },
    search(state, data) {
      let i = state.searchList.findIndex(item => {
        return item == data
      })
      if (i == -1) {
        state.searchList.unshift(data)
      } else {
        state.searchList.splice(i, 1)
        state.searchList.unshift(data)
      }
      if (state.searchList.length > 20) {
        state.searchList.splice(20, 1)
      }
    },
    del(state,i){
      state.searchList.splice(i,1)
    },
    dels(state){
      state.searchList=[]
    }
  },
  actions: {
  },
  getters: {

  },
  modules: {

  },
  //引入插件
  plugins: [vuexLocal.plugin]
})
